# example6_18_box.py
# coding=utf-8
import numpy as np
import matplotlib.pyplot as plt

# 读取鸢尾花数据，一共5列：花萼长度、花萼宽度、花瓣长度、花瓣宽度、鸢尾花种类
data = np.loadtxt("iris.data", delimiter=",", usecols=(0, 1, 2, 3))
# print(data)
plt.rcParams["font.sans-serif"] = "SimHei"  # 设置中文字体

plt.boxplot(
    x=data,
    showmeans=True,
    # 每个箱线图的标签
    labels=["花萼长度", "花萼宽度", "花瓣长度", "花瓣宽度"],
    # 箱体属性：边框颜色和线框的粗细
    boxprops={"color": "blue", "linewidth": "2"},
    # 异常值属性：点的形状和填充色
    flierprops={"marker": "o", "markerfacecolor": "green"},
    # 中位数线的属性：线的类型和颜色
    medianprops={"linestyle": "--", "color": "red"},
)

# 设置刻度字体大小
plt.xticks(fontsize=15)
plt.yticks(fontsize=15)
plt.title("鸢尾花花萼和花瓣尺寸箱线图（单位：cm）", fontsize=15)
plt.show()
